#include<iostream>
#include<cmath>
using namespace std;
typedef long long LL;
const int N = 1e5 + 10;
LL n, m;	
int main()
{
	cin >> n >> m;
	LL a = abs(n - m);
	LL b = n + m;
	bool flag = 0;
	LL ans = 0;
	for (int i = 0; i < 64; i++) {
		if (b >> i & 1) {
			ans += pow(n, i);
		}
	}
	if (ans == b)flag = 1;
	if (flag) {
		cout << "YES" << endl;
		return 0;
	}
	ans = 0;
	for (int i = 0; i < 64; i++) {
		if (a >> i & 1) {
			ans += pow(n, i);
		}
	}
	if (ans == a)flag = 1;
	if (flag) {
		cout << "YES" << endl;
		return 0;
	}
	cout << "NO" << endl;
	return 0;
}	